<?php

namespace App\Models;

use Mockery\Exception;

class EquipmentLevel extends Base
{
    public $timestamps = false;
    protected $connection = 'mysql_center';
    protected $table = 'electric_equipment_level';

    /**
     * @Notes 获取列表
     * @param null $where
     * @param string $order
     * @param string $sort
     * @param null $field
     * @param int $limit
     * @return mixed
     * @author ypp
     * @date 2021/3/23
     * @time 13:51
     */
    public function getList($where = null,$order = 'id',$sort = 'desc',$field = null,$limit = 15)
    {
        $model = self::where($where);
        if(isset($order)){
            $model = $model -> orderBy($order,$sort);
        }
        return $model -> select() -> paginate($limit) -> toArray();
    }

    // 添加
    public function create($data)
    {
        return self::addInfo($data);
    }

    // 修改
    public function edit($data)
    {
        return self::updateByWhere( ['id' => $data['id']] , $data );
    }

    // 删除
    public function deletes($ids)
    {
        $ids = explode(',',$ids);
        try {
            foreach ($ids as $key => $val){
                self::delByWhere(['id' => $val]);
            }
            return true;
        }catch (Exception $exception){
            return false;
        }
    }
}
